package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.*;
import com.vf.admin.utils.StringEx;
import org.apache.hadoop.yarn.webapp.hamlet.Hamlet;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows10</p>
 *
 * @Author : NemoMeng
 * @Date 2023/6/27 11:07
 */
@Repository
public class AfterAlipayConfigsDao extends BaseDao<AlipayConfigs> {

    /**
     * 列表
     *
     * @param paraMap
     * @param splitPage
     * @return
     */
    public List<AlipayConfigs> list(Map<String, Object> paraMap, SplitPageBean splitPage) {
        List<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT a.* FROM alipay_configs a where 1=1 ");
        //条件
        if (StringEx.isNotNull(paraMap.get("status"))) {
            sbStr.append(" and a.status = ? ");
            paramList.add(paraMap.get("status"));
        }
        sbStr.append(" order by a.weight desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AlipayConfigs.class, splitPage);
    }

    /**
     * 删除
     *
     * @param id
     */
    public void del(Integer id) {
        if (id == null || id <= 0) {
            return;
        }
        String sql = "delete from alipay_configs where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 根据id获取
     *
     * @param id
     * @return
     */
    public AlipayConfigs get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from alipay_configs where id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AlipayConfigs.class);
    }

    /**
     * 保存或是修改
     *
     * @param param
     */
    public void saveOrUpdate(AlipayConfigs param) {
        if (param.getId() != null && param.getId() > 0) {
            this.update(param);
        } else {
            param.setId(this.add(param));
        }
    }
}
